﻿$(function () {

    //date validate
    jQuery.validator.unobtrusive.adapters.add('rangeyearvalidation', ['mindate', 'maxdate'], function (options) {
        options.rules['rangeyearvalidation'] = options.params;
        options.messages['rangeyearvalidation'] = options.message;
    });

    jQuery.validator.addMethod('rangeyearvalidation', function (value, element, params) {
        var date = Date.parse(value);
        if (isNaN(date)) return false;
        else {
            if (typeof (date) != 'number') return false;
            else {
                var mindate = Date.parse(params.mindate);
                var maxdate = Date.parse(params.maxdate);
                if (isNaN(mindate) || isNaN(maxdate)) return true;
                return mindate < date && maxdate > date;
            }
        }
    });

    //weight validate
    jQuery.validator.unobtrusive.adapters.add('weightvalidation', ['maxweight'], function (options) {
        options.rules['weightvalidation'] = options.params;
        options.messages['weightvalidation'] = options.message;
    });

    jQuery.validator.addMethod('weightvalidation', function (value, element, params) {
        var weight = parseFloat(value);
        if (isNaN(weight)) return false;
        else {
            if (typeof (weight) != 'number') return false;
            else {
                if (isNaN(params.maxweight)) return true;
                return weight < params.maxweight && weight>0;
            }
        }
    });

    //weight validate
    jQuery.validator.unobtrusive.adapters.add('heightvalidation',['maxheight'],function(options) {
        options.rules['heightvalidation'] = options.params;
        options.messages['heightvalidation'] = options.message;
    });
    
    jQuery.validator.addMethod('heightvalidation', function (value, element, params) {
        var height = parseFloat(value);
        if (isNaN(height)) return false;
        else {
            if (typeof (height) != 'number') return false;
            else {
                if (isNaN(params.maxheight)) return true;
                return height < params.maxheight && height > 0;
            }
        }
    });
});